{$CLEO .qa}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "FORSLQA"

// By ArtemQa146

const
    gang_man = 31@
    gang_check = 30@

    Event = 27@
    coords_x = 26@
    coords_y = 25@
    coords_z = 24@
    angle_1 = 23@
    obj_1 = 21@
    render_h = 19@
    ped_id = 18@
    obj_2 = 17@
    obj_3 = 16@
end

0087: coords_x = 0@ // (float)
0087: coords_y = 1@ // (float)
0087: coords_z = 2@ // (float)
0087: angle_1 = 3@ // (float)

if
    0E4D: random_percent 30
then
else
    repeat
    wait 0
    until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 150.0
    0A93: terminate_this_custom_script
end

0209: 1@ = random_int_in_ranges 1 5
if 1@ == 1
then ped_id = 60
end
if 1@ == 2
then ped_id = 95
end
if 1@ == 3
then ped_id = 183
end
if 1@ == 4
then ped_id = 188
end

repeat
wait 0
04ED: load_animation  "PedEventsMod"
until 04EE:   animation "PedEventsMod" loaded

model.Load(ped_id)
model.Load(3262)
if
    not model.Available(ped_id)
then
    repeat
    wait 0
    model.Load(ped_id)
    until model.Available(ped_id)
end
if
    not model.Available(3262)
then
    repeat
    wait 0
    model.Load(3262)
    until model.Available(3262)
end

038B: load_requested_models
coords_z -= 1.0
0E01: create_object_no_save 3262 at coords_x coords_y coords_z offset 0 ground 0 to obj_1
0E01: create_object_no_save 3262 at coords_x coords_y coords_z offset 0 ground 0 to obj_2
0E01: create_object_no_save 3262 at coords_x coords_y coords_z offset 0 ground 0 to obj_3
0177: set_object obj_1 Z_angle_to angle_1
0177: set_object obj_2 Z_angle_to angle_1
0177: set_object obj_3 Z_angle_to angle_1

0400: store_coords_to 1@ 2@ 3@ from_object obj_1 with_offset 0.0 0.55 0.0

009A: gang_man = create_actor_pedtype 21 model ped_id at 1@ 2@ 3@
angle_1 += 180.0
0173: set_actor gang_man Z_angle_to angle_1

0812: AS_actor gang_man perform_animation "forsale" IFP "PedEventsMod" framedelta 100.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1

0F02: create_render_object_to_char_bone_from_special gang_man special_model 4@ bone 24 offset 0 0 0 rotation 0 0 0 store_to render_h
0F04: create_render_object_to_object_from_special obj_1 special_model 5@ offset 0 0 0 rotation 0 0 0 store_to 1@
0F04: create_render_object_to_object_from_special obj_2 special_model 5@ offset 0 0 0 rotation 0 0 0 store_to 2@
0F04: create_render_object_to_object_from_special obj_3 special_model 5@ offset 0 0 0 rotation 0 0 0 store_to 3@
08D2: object obj_1 scale_model 0.0
08D2: object obj_2 scale_model 0.0
08D2: object obj_3 scale_model 0.0
0E37: set_render_object_scale 1@ 1.3 1.3 1.3
0E37: set_render_object_scale 2@ 1.3 1.3 1.3
0E37: set_render_object_scale 3@ 1.3 1.3 1.3
07F7: set_object obj_1 destructible 0
07F7: set_object obj_2 destructible 0
07F7: set_object obj_3 destructible 0

model.Destroy(3262)
model.Destroy(ped_id)

timera = 0

wait 300

repeat
wait 0
    if
        056D:   actor gang_man defined
    then

        // , ,    
        080E: get_actor $PLAYER_ACTOR ped_event_to 2@
        080E: get_actor gang_man ped_event_to 3@
        if or
            actor.Dead(gang_man)
            2@ == 11
            3@ == 49
            3@ == 9
            051A:   actor gang_man damaged_by_actor $PLAYER_ACTOR
            not is_char_script_controlled gang_man
            not locate_char_distance_to_coordinates gang_man pos coords_x coords_y coords_z radius 3.0
        then
            break
        end
        
        080E: get_actor gang_man ped_event_to 2@
        if or
            2@ == 15
            2@ == 31
            2@ == 59
        then
            break
        end

        if
            not $ACTIVE_INTERIOR == 0
        then
            break
        end

        //    
        if
            0457:   player $PLAYER_CHAR aiming_at_actor gang_man
        then
            0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 2@
            0E89: get_weaponinfo_fire_type 2@ store_to 3@ //     
            if or
                3@ == 1 //  
                3@ == 3 //   (  ..)
            then
                break
            end
        end

        if
            0EE4: locate_char_distance_to_char $PLAYER_ACTOR char gang_man radius 20.0
        then


                if
                    0611:   actor gang_man performing_animation "forsale"
                then
                    0613: 1@ = actor gang_man animation "forsale" time
                    if
                        1@ > 0.95
                    then
                        if
                            timerb > 20000
                        then
                            0812: AS_actor gang_man perform_animation "forsale2" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
                            wait 300
                        end
                        timera = 0
                        continue
                    end
                end


        else
            timerb = 0
        end

            if
                0611:   actor gang_man performing_animation "forsale2"
            then
                0613: 1@ = actor gang_man animation "forsale2" time
                if
                    1@ > 0.95
                then
                    break
                end
            end


    else
        break
    end
until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 120.0
04EF: release_animation "PedEventsMod"

if
    0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 50.0
then
    if 056D:   actor gang_man defined
    then
        0E31: set_render_object_visible render_h 0
        01C2: remove_references_to_actor gang_man // Like turning an actor into a random pedestrian
    end
    if 03CA:   object obj_1 exists
    then 01C4: remove_references_to_object obj_1 // This object will now disappear when the player looks away
    end
    if 03CA:   object obj_2 exists
    then 01C4: remove_references_to_object obj_2 // This object will now disappear when the player looks away
    end
    if 03CA:   object obj_3 exists
    then 01C4: remove_references_to_object obj_3 // This object will now disappear when the player looks away
    end
else
    if 056D:   actor gang_man defined
    then 009B: destroy_actor gang_man
    end
    if 03CA:   object obj_1 exists
    then 0108: destroy_object obj_1
    end
    if 03CA:   object obj_2 exists
    then 0108: destroy_object obj_2
    end
    if 03CA:   object obj_3 exists
    then 0108: destroy_object obj_3
    end
end

repeat
wait 0
until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 100.0

0A93: terminate_this_custom_script

